import requests



res = requests.get("https://fapi.binance.com/fapi/v1/historicalTrades?symbol=BTCUSDT&limit=10")

res = requests.get("https://fapi.binance.com/fapi/v1/aggTrades?symbol=BTCUSDT&limit=10")
print(res.json())













# # 定义请求的URL和参数
# base_url = "https://fapi.binance.com"
# endpoint = "/fapi/v1/historicalTrades"
# params = {
#     "symbol": "BTCUSDT",
#     "limit": 10  # 获取10条记录
# }
#
# # 发送GET请求（无需API密钥）
# response = requests.get(base_url + endpoint, params=params)
#
# # 检查请求是否成功
# if response.status_code == 200:
#     trades = response.json()
#     for trade in trades:
#         # 将时间戳转换为可读时间
#         from datetime import datetime
#         trade_time = datetime.fromtimestamp(trade['time'] / 1000)
#         print(f"ID: {trade['id']}, Time: {trade_time}, Price: {trade['price']}, Qty: {trade['qty']}, Maker is Buyer: {trade['isBuyerMaker']}")
# else:
#     print("请求失败，错误代码:", response.status_code)
#     print("错误信息:", response.text)